package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CourseComments;
import com.ruoyi.system.service.ICourseCommentsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课堂评论Controller
 * 
 * @author zrj
 * @date 2025-07-15
 */
@RestController
@RequestMapping("/system/courseComments")
public class CourseCommentsController extends BaseController
{
    @Autowired
    private ICourseCommentsService courseCommentsService;

    /**
     * 查询课堂评论列表
     */
    @PreAuthorize("@ss.hasPermi('system:courseComments:list')")
    @GetMapping("/list")
    public TableDataInfo list(CourseComments courseComments)
    {
        startPage();
        List<CourseComments> list = courseCommentsService.selectCourseCommentsList(courseComments);
        return getDataTable(list);
    }

    /**
     * 导出课堂评论列表
     */
    @PreAuthorize("@ss.hasPermi('system:courseComments:export')")
    @Log(title = "课堂评论", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CourseComments courseComments)
    {
        List<CourseComments> list = courseCommentsService.selectCourseCommentsList(courseComments);
        ExcelUtil<CourseComments> util = new ExcelUtil<CourseComments>(CourseComments.class);
        util.exportExcel(response, list, "课堂评论数据");
    }

    /**
     * 获取课堂评论详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:courseComments:query')")
    @GetMapping(value = "/{commentUid}")
    public AjaxResult getInfo(@PathVariable("commentUid") Long commentUid)
    {
        return success(courseCommentsService.selectCourseCommentsByCommentUid(commentUid));
    }

    /**
     * 新增课堂评论
     */
    @PreAuthorize("@ss.hasPermi('system:courseComments:add')")
    @Log(title = "课堂评论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CourseComments courseComments)
    {
        return toAjax(courseCommentsService.insertCourseComments(courseComments));
    }

    /**
     * 修改课堂评论
     */
    @PreAuthorize("@ss.hasPermi('system:courseComments:edit')")
    @Log(title = "课堂评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CourseComments courseComments)
    {
        return toAjax(courseCommentsService.updateCourseComments(courseComments));
    }

    /**
     * 删除课堂评论
     */
    @PreAuthorize("@ss.hasPermi('system:courseComments:remove')")
    @Log(title = "课堂评论", businessType = BusinessType.DELETE)
	@DeleteMapping("/{commentUids}")
    public AjaxResult remove(@PathVariable Long[] commentUids)
    {
        return toAjax(courseCommentsService.deleteCourseCommentsByCommentUids(commentUids));
    }
}
